package com.example.WebSocketDemo.web;

import com.example.WebSocketDemo.bean.Friend;
import com.example.WebSocketDemo.bean.FriendRequest;
import com.example.WebSocketDemo.bean.User;
import com.example.WebSocketDemo.service.FriendRequestService;
import com.example.WebSocketDemo.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/friend")
public class FriendRequestController {
    @Autowired
    private FriendRequestService friendRequestService;

    @GetMapping("/request")
    public Result getFriendRequest(String username){
        return Result.success(friendRequestService.getFriendRequestByUsername(username));
    }

    @PostMapping("/request/reject")
    public Result rejectRequest(String id){
        friendRequestService.rejectRequest(id);
        return Result.success();
    }

    @PostMapping("/request/agree")
    public Result agreetRequest(String id){
        friendRequestService.agreeRequest(id);
        return Result.success();
    }

    @PostMapping("/request/add")
    public Result friendAdd(@RequestBody Friend friendRequest){
        friendRequestService.addFriend(friendRequest);
        return Result.success();
    }


}
